from time import sleep

from selenium import webdriver

driver = webdriver.Firefox()
# driver.get('https://email.163.com/#from=ntes_product')

# 从百度搜索进入163邮箱登录
driver.get('https://www.baidu.com')
sleep(2)

key_word = driver.find_element_by_id('kw').send_keys('163邮箱登录')
sleep(2)
bt = driver.find_element_by_id('su').click()
sleep(2)
driver.find_element_by_css_selector('div.result:nth-child(1) > h3:nth-child(1)').click()
sleep(2)


driver.switch_to.window(driver.window_handles[-1])




# 进入163登录界面
# 定位框架
#找到iframe
iframe = driver.find_element_by_xpath('//div[@id="loginDiv"]/iframe')
#切换到iframe
driver.switch_to.frame(iframe)


# 账号密码
driver.find_element_by_name('email').send_keys('atom613')

driver.find_element_by_name('password').send_keys('613atom666')

# 点击登录
css_path = '#dologin'
driver.find_element_by_css_selector(css_path).click()
sleep(5)

# 新页面，回初始框架
driver.switch_to.default_content()

writel = driver.find_elements_by_css_selector('div nav div ul li')[1]

writel.click()

sleep(5)

receiver = driver.find_element_by_css_selector('header div div div div div input')

receiver.send_keys('ma_linpop@163.com')

title = driver.find_elements_by_css_selector('div section header div div div input')[2]

title.send_keys('化工学院_计173班_郭纾怡 自动化发送邮件')
sleep(2)

driver.switch_to.frame(driver.find_element_by_css_selector('.APP-editor-iframe'))

letter=driver.find_element_by_css_selector('body')

letter.send_keys('吃葡萄不吐葡萄皮！！！')
sleep(2)

driver.switch_to.default_content()

# 发送按钮
send=driver.find_elements_by_css_selector('header div div div[role="button"]')[0]
send.click()

# driver.quit()